package algorithm.easy;

public class Solution101 {

    //输入：root = [1,2,2,3,4,4,3]
    //输出：true
    public static boolean isSymmetric(TreeNode root) {
        if(root==null){
            return true;
        }
        return compare(root,root) ;
    }

    private static boolean compare(TreeNode node1,TreeNode node2){
        if(node1==null && node2==null){
            return true;
        }
        if(node1 ==null||node2==null){
            return false;
        }
        boolean flag = false;
        if(node1.val==node2.val){
            TreeNode left1 = node1.left;
            TreeNode right1 = node2.right;
            TreeNode left2 = node1.right;
            TreeNode right2 = node2.left;
            flag = compare(left1,right1) && compare(left2,right2);
        }else{
            flag = false;
        }

        return flag;
    }

    public static void main(String[] args){
        TreeNode node = TreeNode.init101();
        System.out.println(isSymmetric(node));
    }


}
